<?php
class ds extends CI_Controller {
	function index() {
		$this->pub->logp('浏览实时日志','2');
		$da = $this -> pub -> get_setting('实时日志', 'Instant Logs');
		$this -> load -> view('adminx/ds', $da);
	}

	function get() {
		$this->pub->logp('获取实时日志信息','2');
		$day1 = strtotime($this -> input -> post('day1'));
		$day2 = strtotime($this -> input -> post('day2')) + 86400;

		$this -> db -> where('mktime >', $day1);
		$this -> db -> where('mktime <', $day2);
		
		$this -> db -> select('count(*)');
		$q = $this -> db -> get_where('ds');
		$ls = $q -> row_array(0);
		$num = $ls['count(*)'];
		//一共的页数
		$da['num'] = ceil($num / 30);

		$page = is_numeric($this -> input -> post('page')) && $this -> input -> post('page') > 0 ? $this -> input -> post('page') : 1;
		$page = $page > $da['num'] ? $da['num'] : $page;
		$da['page'] = $page;

		$page = ($page - 1) == -1 ? 0 : ($page - 1);

		$this -> db -> limit(30, $page * 30);
		$this -> db -> order_by('id', 'desc');
		$this -> db -> where('mktime >', $day1);
		$this -> db -> where('mktime <', $day2);
		$q = $this -> db -> get_where('ds');
		$da['content'] = '';
		foreach ($q->result_array() as $v) {
			$da['content'] .= '<tr>';
			$da['content'] .= '<td>' . $v['id'] . '</td>';
			$da['content'] .= '<td>' . $v['content'] . '</td>';
			$da['content'] .= '<td>' . date('Y-m-d H:i:s', $v['mktime']) . '</td>';
			$da['content'] .= '</tr>';
		}
		$da['type'] = 1;
		echo json_encode($da);
	}

}
?>